Skip to content

Conversation

@dabrt
Copy link
Contributor

@dabrt dabrt commented Nov 6, 2025

Question Answer
JIRA Ticket IBX-10885
Versions 4.6, 5.0
Edition all

Document Content Type search API

Checklist

  • Text renders correctly
  • Text has been checked with vale
  • Description metadata is up to date
  • Code samples are working
  • PHP code samples have been fixed with PHP CS fixer
  • Added link to this PR in relevant JIRA ticket or code PR

@github-actions
Copy link

github-actions bot commented Nov 6, 2025

@dabrt dabrt requested a review from barw4 November 7, 2025 12:30
@github-actions
Copy link

github-actions bot commented Nov 7, 2025

code_samples/ change report

Before (on target branch)After (in current PR)

code_samples/api/public_php_api/src/Command/FindContentTypeCommand.php


code_samples/api/public_php_api/src/Command/FindContentTypeCommand.php

docs/content_management/content_api/managing_content.md@180:```php hl_lines="12-17"
docs/content_management/content_api/managing_content.md@181:[[= include_file('code_samples/api/public_php_api/src/Command/FindContentTypeCommand.php', 17, 43) =]]
docs/content_management/content_api/managing_content.md@182:```

001⫶class FindContentTypesCommand extends Command
002⫶{
003⫶ public function __construct(private readonly ContentTypeService $contentTypeService)
004⫶ {
005⫶ parent::__construct();
006⫶ }
007⫶
008⫶ protected function execute(InputInterface $input, OutputInterface $output): int
009⫶ {
010⫶ // Find content types whose identifier is "folder" or "article",
011⫶ // or content type "user"
012❇️ $query = new ContentTypeQuery(
013❇️ new Criterion\LogicalOr([
014❇️ new Criterion\LogicalAnd([
015❇️ new Criterion\ContentTypeIdentifier(['folder', 'article']),
016❇️ ]),
017❇️ new Criterion\ContentTypeIdentifier(['user']),
018⫶ ]),
019⫶ [
020⫶ new SortClause\Id(),
021⫶ new SortClause\Identifiers(),
022⫶ new SortClause\Name(),
023⫶ ]
024⫶ );
025⫶
026⫶ $searchResult = $this->contentTypeService->findContentTypes($query);

docs/search/content_type_search_reference/content_type_sort_clauses.md@22:```php hl_lines="37-39"
docs/search/content_type_search_reference/content_type_sort_clauses.md@23:[[= include_file('code_samples/api/public_php_api/src/Command/FindContentTypeCommand.php') =]]
docs/search/content_type_search_reference/content_type_sort_clauses.md@24:```

001⫶<?php declare(strict_types=1);
002⫶
003⫶namespace App\Command;
004⫶
005⫶use Ibexa\Contracts\Core\Repository\ContentTypeService;
006⫶use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;
007⫶use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion;
008⫶use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause;
009⫶use Symfony\Component\Console\Attribute\AsCommand;
010⫶use Symfony\Component\Console\Command\Command;
011⫶use Symfony\Component\Console\Input\InputInterface;
012⫶use Symfony\Component\Console\Output\OutputInterface;
013⫶
014⫶#[AsCommand(
015⫶ name: 'doc:find_content_types',
016⫶ description: 'Lists content types that match specific criteria.'
017⫶)]
018⫶class FindContentTypesCommand extends Command
019⫶{
020⫶ public function __construct(private readonly ContentTypeService $contentTypeService)
021⫶ {
022⫶ parent::__construct();
023⫶ }
024⫶
025⫶ protected function execute(InputInterface $input, OutputInterface $output): int
026⫶ {
027⫶ // Find content types whose identifier is "folder" or "article",
028⫶ // or content type "user"
029⫶ $query = new ContentTypeQuery(
030⫶ new Criterion\LogicalOr([
031⫶ new Criterion\LogicalAnd([
032⫶ new Criterion\ContentTypeIdentifier(['folder', 'article']),
033⫶ ]),
034⫶ new Criterion\ContentTypeIdentifier(['user']),
035⫶ ]),
036⫶ [
037❇️ new SortClause\Id(),
038❇️ new SortClause\Identifiers(),
039❇️ new SortClause\Name(),
040⫶ ]
041⫶ );
042⫶
043⫶ $searchResult = $this->contentTypeService->findContentTypes($query);
044⫶
045⫶ $output->writeln('Found ' . $searchResult->totalCount . ' content types:');
046⫶
047⫶ foreach ($searchResult->searchHits as $searchHit) {
048⫶ $contentType = $searchHit->valueObject;
049⫶ $output->writeln(sprintf(
050⫶ '- [%d] %s (identifier: %s)',
051⫶ $contentType->id,
052⫶ $contentType->getName(),
053⫶ $contentType->identifier
054⫶ ));
055⫶ }
056⫶
057⫶ return Command::SUCCESS;
058⫶ }
059⫶}

Download colorized diff

new Criterion\LogicalAnd([
new Criterion\ContentTypeIdentifier(['folder', 'article']),
]),
new Criterion\ContentTypeIdentifier(['user']),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make sense to use some different criterion here -> maybe ContentTypeGroupName. The current one doesn't make a lot of sense because it could be simply put into one criterion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just relied on an example given in your PR. We can add ContentTypeGroupName in a follow up PR, WDYS?

Copy link

@barw4 barw4 Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use something else than new Criterion\ContentTypeIdentifier(['user']), it can be even ContentTypeGroupId. The current example is not a proper one, these criteria:

            new Criterion\LogicalOr([
                new Criterion\LogicalAnd([
                    new Criterion\ContentTypeIdentifier(['folder', 'article']),
                ]),
                new Criterion\ContentTypeIdentifier(['user']),

shouldn't be composed like that. LogicalAnd doesn't make sense without at least two criterions inside. All this logic could be replaced with:
new Criterion\ContentTypeIdentifier(['folder', 'article', 'user'])

Let's keep this example grounded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants